<?

if ($DATA['component']['id']) {
	
	$_record = array('id_data' => D_MB_SETTINGS, 'id_parent' => $DATA['component']['id']);
	$_defaults = array('per_page' => 10, 'api_key' => '', 'domain' => $_SERVER['HTTP_HOST']);

	$_record = array('id_data' => D_MB_SETTINGS, 'id_parent' => $DATA['component']['id'], 'assoc' => '');
	$_defaults = array('bank_mfo' => "300346", 'currencies' => 'USD,EUR,RUR');
	$_def_multilang = array(
		'ua' => array('title' => 'Курси валют', 'buy' => 'купівля', 'sell' => 'продаж'), 
		'en' => array('title' => 'Курсы валют', 'buy' => 'buy', 'sell' => 'sell'), 
		'ru' => array('title' => 'Exchange Rates', 'buy' => 'покупка', 'sell' => 'продажа'));

	switch (action(array('editor_save'))) {
	
		case 'editor_save':

			$temp = array();
			
			foreach($_defaults as $k => $v)
				if (($t = trim(postdata($k))) !== '')
					$temp[] = array_merge($_record, array('name' => $k, 'value' => $t));	// language independent data

			foreach($DATA['langs'] as $lang)
				foreach($_def_multilang[$lang['text']] as $k => $v)
					if (isset($_POST[$k][$lang['text']]) && (($t = trim($_POST[$k][$lang['text']])) !== ''))
						$temp[] = array_merge($_record, array('name' => $k, 'value' => $t, 'assoc' => $lang['text']));	// language dependent data
			

			dataset('db_delete', tb('data'), "(id_data=".D_MB_SETTINGS.") AND (id_parent={$DATA[component][id]})");
			dataset('db_insert', tb('data'), $temp);
			
			return true;	// end of component edition
	}


	$DATA['settings'] = array('data' => $_def_multilang);	// load defaults

	$temp = datafetch_array('db_list', array(
		'table' => tb('data'), 
		'where' => "(id_data=".D_MB_SETTINGS.") AND (id_parent={$DATA[component][id]}) AND (assoc='')", 
		'index' => 'name' ));

	foreach($_defaults as $k => $v)
		$DATA['settings'][$k] = isset($temp[$k]) ? $temp[$k]['value'] : $v;	// load language independent data

	$temp = datafetch_array('db_list', array('table' => tb('data'), 'where' => "(id_data=".D_MB_SETTINGS.") AND (id_parent={$DATA[component][id]}) AND (assoc!='')"));
	
	foreach($temp as $k => $v)	
		$DATA['settings']['data'][$v['assoc']][$v['name']] = $v['value'];	// load language dependent data
	
		
	return false;

} else exit;

?>